package com.back.network.web.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.back.network.netty.dto.AccountDTO;
import com.back.network.web.entity.User;

//该类名无需与mapping映射的类名相同
public interface UserDao {

	@Select("select count(id) from user where account = #{account} and password= #{password}")
	int login(User user);

	/** 通过账户密码获取用户信息 **/
	@Select("select * from user where account = #{account} and password = #{password}")
	User getUser(User user);
	
	@Select("SELECT email FROM user WHERE email=#{accountOremail} OR account=#{accountOremail} LIMIT 0,1")
	String getEmailByAccountOrEmail(String accountOremail);

	/** 账户是否存在 **/
	@Select("SELECT count(id) FROM user WHERE account = #{account}")
	int isExistAccount(AccountDTO accountDTO);

	/** 邮箱是否存在 **/
	@Select("SELECT count(id) FROM user WHERE email = #{email}")
	int isExistEmail(AccountDTO accountDTO);

	@Insert("INSERT INTO user (account,PASSWORD,domain,email) VALUE(#{dto.account},#{dto.password},#{domain},#{dto.email})")
	int save(@Param("dto") AccountDTO accountDTO, @Param("domain") String domain);
	
	@Update("UPDATE user SET state = 1 WHERE email = #{email}")
	void updateStateByEmail(String email);
	
	@Update("UPDATE user SET password = #{password} WHERE email=#{emailOrAccount} OR account=#{emailOrAccount}")
	void updatePasswordByEmailOrAccount(@Param("password")String password,@Param("emailOrAccount")String emailOrAccount);

}
